<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body style="font-family:Arial, '微软雅黑', '宋体'; font-size:12px;">
<?php

sliceBanner();

echo '<script>parent.document.getElementById("mask").remove();parent.document.getElementById("maskTop").remove();</script>';


function sliceBanner()
{

	$x = (int)$_POST['x1'];
	$y = (int)$_POST['y1'];
	
	$x2 = (int)$_POST['x2'];
	$y2 = (int)$_POST['y2']; 
	
	$ssw = (int)$_POST['ss_w']; 
	$ssh = (int)$_POST['ss_h'];
	
	$filename = trim($_POST['pic']);
	$cwmurl =  '../../../upload/image/'. substr($filename,0,7).'/'.$filename;
	$sizearr = @getimagesize($cwmurl);
	
//echo "
//x：{$x}<br />
//y：{$y}<br />
//x2：{$x2}<br />
//y2：{$y2}<br />
//
//ssw：{$ssw}<br />
//ssh：{$ssh}<br />
//
//";

	$new_x = ($x/$ssw)*$sizearr[0];
	$new_y = ($y/$ssh)*$sizearr[1];
	
	$new_x2 = ($x2/$ssw)*$sizearr[0];
	$new_y2 = ($y2/$ssh)*$sizearr[1];
	
	$new_w = $new_x2-$new_x;
	$new_h = $new_y2-$new_y;
	
	if(isset($filename)) {
	
		$uploadBanner =  '../../../upload/image/'. substr($filename,0,7).'/'.$filename;
		$sliceBanner = '../../../upload/image/'. substr($filename,0,7).'/'.$filename;
		$src_pic = getImageHander($uploadBanner);
		
		if(!$src_pic){
		echo 0.1;exit;
		}
		
		$dst_pic = imagecreatetruecolor($new_w, $new_h);
		imagecopyresampled($dst_pic, $src_pic, 0, 0, $new_x, $new_y, $new_w, $new_h, $new_w, $new_h);
		imagejpeg($dst_pic, $sliceBanner);
		imagedestroy($src_pic);
		imagedestroy($dst_pic);
		echo '处理后效果：<br><img src="'.$sliceBanner.'" width="50%"><br>处理完成后直接关闭“图片上传”窗口即可！';exit;
	}
	echo 0.2;exit;
}

function getImageHander ($url)
{
	$size=@getimagesize($url);
	switch($size['mime']){
		case 'image/jpeg': $im = imagecreatefromjpeg($url);break;
		case 'image/gif' : $im = imagecreatefromgif($url);break;
		case 'image/png' : $im = imagecreatefrompng($url);break;
		default: $im=false;break;
	}
	return $im;
}
?>
</body>
</html>
